package states;

import monitor.StateVariableMonitor;
import gui.OpCom;
import regulators.BallAndBeamRegul;
import regulators.BeamRegul;
import se.lth.control.realtime.DigitalIn;
import se.lth.control.realtime.DigitalOut;

public class Drop extends StateClass implements State {

	public Drop(DigitalIn initialPosSensor, DigitalOut digitalSolenoid, BeamRegul beam,
			BallAndBeamRegul ballAndBeam,OpCom op, StateVariableMonitor stateVariableMonitor) {
		super(initialPosSensor, digitalSolenoid, beam, ballAndBeam, op, stateVariableMonitor);
	}
	private double step;

	@Override
	public void initialExcecution() {
		op.displayStep("Drop");
		ballAndBeam.shutDown();
		beam.restart();
		step = -0.5;
	}

	@Override
	public void excecute() {
		step = step - 0.02;
		beam.setRef(step);
	}


	@Override
	public boolean stateOfExcecution() {
		return step <= -7? true:false;
	}

	@Override
	public void nextState() {
		setCurrentState(new ResetState(initialPosSensor, digitalSolenoid, beam, ballAndBeam,op, stateVariableMonitor));
	}

	@Override
	public void suspend() {
		beam.shutDown();

	}

	@Override
	public void resume() {
		this.initialExcecution();

	}

}
